﻿<EditForm Model="@TestModel" OnValidSubmit="@HandleValidSubmit" OnInvalidSubmit="@HandleInvalidSubmit">
    <DataAnnotationsValidator />

    <BitNumberField Min="@Min"
                    Max="@Max"
                    Step="@Step"
                    @bind-Value="@TestModel.Value"
                    IsEnabled="@IsEnabled"
                    AriaDescription="@AriaDescription"
                    AriaPositionInSet="@AriaPositionInSet"
                    AriaSetSize="@AriaSetSize"
                    AriaValueNow="@AriaValueNow"
                    AriaValueText="@AriaValueText"
                    AriaLabel="@AriaLabel"
                    Suffix="@Suffix"
                    InlineLabel="@InlineLabel"
                    IconName="@IconName"
                    IconAriaLabel="@IconAriaLabel"
                    DecrementIconName="@DecrementIconName"
                    IncrementIconName="@IncrementIconName"
                    DecrementAriaLabel="@DecrementAriaLabel"
                    IncrementAriaLabel="@IncrementAriaLabel"
                    Label="@Label"
                    Placeholder="@Placeholder"
                    InputHtmlAttributes="@InputHtmlAttributes"
                    Title="@Title"
                    DefaultValue="@DefaultValue"
                    OnChange="(int? value) => OnChangeEventValue = value"
                    OnBlur="@HandleBlur"
                    OnFocus="@HandleFocus">
        <LabelTemplate>
            @LabelTemplate
        </LabelTemplate>
    </BitNumberField>

</EditForm>

@code {
    [Parameter] public bool InlineLabel { get; set; }
    [Parameter] public string? AriaDescription { get; set; }
    [Parameter] public int? AriaPositionInSet { get; set; }
    [Parameter] public int? AriaSetSize { get; set; }
    [Parameter] public int? AriaValueNow { get; set; }
    [Parameter] public string? AriaValueText { get; set; }
    [Parameter] public string? AriaLabel { get; set; }
    [Parameter] public string? Min { get; set; }
    [Parameter] public string? Max { get; set; }
    [Parameter] public string Step { get; set; } = "1";
    [Parameter] public BitNumberFieldTestModel TestModel { get; set; } = new();
    [Parameter] public EventCallback<int> ValueChanged { get; set; }
    [Parameter] public string Suffix { get; set; } = string.Empty;
    [Parameter] public string? IconName { get; set; }
    [Parameter] public string Label { get; set; } = string.Empty;
    [Parameter] public string? Placeholder { get; set; }
    [Parameter] public Dictionary<string, object>? InputHtmlAttributes { get; set; }
    [Parameter] public string? Title { get; set; }
    [Parameter] public string? DecrementIconName { get; set; }
    [Parameter] public string? IncrementIconName { get; set; }
    [Parameter] public int DefaultValue { get; set; }
    [Parameter] public string IconAriaLabel { get; set; } = string.Empty;
    [Parameter] public string? DecrementAriaLabel { get; set; }
    [Parameter] public string? IncrementAriaLabel { get; set; }
    [Parameter] public bool IsEnabled { get; set; } = true;
    [Parameter] public RenderFragment? LabelTemplate { get; set; }

    public int OnIncrementEventCounter { get; set; }
    public int OnBlurEventCounter { get; set; }
    public int OnFocusEventCounter { get; set; }
    public int OnDecrementEventCounter { get; set; } = 20;
    public int? OnChangeEventValue { get; set; }
    public int ValidCount { get; set; }
    public int InvalidCount { get; set; }

    private void HandleChange(int? value)
    {
        OnChangeEventValue = value;
    }

    private void HandleBlur(FocusEventArgs args)
    {
        OnBlurEventCounter++;
    }

    private void HandleFocus(FocusEventArgs args)
    {
        OnFocusEventCounter++;
    }

    private void HandleDecrement(int? args)
    {
        OnDecrementEventCounter--;
    }

    private void HandleIncrement(int? args)
    {
        OnIncrementEventCounter++;
    }

    private void HandleValidSubmit()
    {
        ValidCount++;
    }

    private void HandleInvalidSubmit()
    {
        InvalidCount++;
    }
}